<?php
class matrix
{
    static private $_arr = array();

    static public function has($resourceName)
    {/*{{{*/
        $resourceName = strtolower($resourceName);
        return isset(self::$_arr[$resourceName]);
    }/*}}}*/

    static public function register($resourceName, $obj)
    {/*{{{*/
        $resourceName = strtolower($resourceName);
        /*if (self::has($resourceName))
        {
            assert(false);
        }*/
        self::$_arr[$resourceName] = $obj;
    }/*}}}*/

    static public function replace($resourceName, $obj)
    {/*{{{*/
        $resourceName = strtolower($resourceName);
        self::$_arr[$resourceName] = $obj;
    }/*}}}*/

    static public function get($resourceName)
    {/*{{{*/
        $resourceName = strtolower($resourceName);
        if (false == self::has($resourceName))
        {
            if ($resourceName == 'debug')
                $res = new Debugger();
            else
                $res = new $resourceName;
            self::$_arr[$resourceName] = $res;
        }
        else
        {
            $res = self::$_arr[$resourceName];
        }
        return $res;
    }/*}}}*/

    static public function destroy($resourceName)
    {/*{{{*/
        $resourceName = strtolower($resourceName);
        unset(self::$_arr[$resourceName]);
    }/*}}}*/

    static public function free()
    {/*{{{*/
        self::$_arr = array();
    }/*}}}*/

    static public function isFree() 
    {
        return empty(self::$_arr);
    }

    static public function dump()
    {/*{{{*/
        return self::$_arr;
    }/*}}}*/

    static public function load($arr)
    {/*{{{*/
        self::$_arr = $arr;
    }/*}}}*/
}
